<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateCoinLogTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('coin_log', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->default(0)->comment('用户ID');
            $table->tinyInteger('log_type')->default(0)->comment('流水类型：1-充值，2-消费，3-收入');
            $table->tinyInteger('from')->default(0)->comment('流水渠道：1-充值，2-新手福利，3-语音消费..');
            $table->double('coin', 10, 1)->default(0.0)->comment('消费数量');
            $table->string('order_id', 50)->default('')->comment('关联内部订单ID');
            $table->timestamps();
            $table->tinyInteger('flag')->default(1)->comment('1-有效，0-无效');
            $table->index('user_id', 'user_id');
            $table->index(['user_id', 'log_type'], 'user_log_type');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('coin_log');
    }
}
